package cn.z2huo.demo.spring.cloud.alibaba.provider.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.z2huo.demo.spring.cloud.alibaba.provider.config.ProviderConfiguration;
import cn.z2huo.demo.spring.cloud.alibaba.provider.config.ProviderConfiguration2;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 * @author z2huo
 */
@RestController
@RequestMapping("/provider/config")
@RequiredArgsConstructor
@EnableConfigurationProperties(ProviderConfiguration2.class)
public class ConfigController {

    private final ProviderConfiguration providerConfiguration;

    private final ProviderConfiguration2 providerConfiguration2;

    @GetMapping("/1/{configName}")
    public String getConfig(@PathVariable String configName) {
        Object property = BeanUtil.getProperty(providerConfiguration, configName);
        return property == null ? "null" : property.toString();
    }

    @GetMapping("/2/{configName}")
    public String getConfig2(@PathVariable String configName) {
        Object property = BeanUtil.getProperty(providerConfiguration2, configName);
        return property == null ? "null" : property.toString();
    }

}
